import cv2 as cv
import numpy as np


def line_detect_demo(image):
    blured = cv.GaussianBlur(image,(3,3),0)
    gray = cv.cvtColor(blured,cv.COLOR_BGR2GRAY)

    edge = cv.Canny(gray,20,150)
    cv.imshow('edge',edge)

    lines = cv.HoughLinesP(edge,1,np.pi/180,20,minLineLength=40,maxLineGap=5)
    for line in lines:
        x1,y1,x2,y2 = line[0]
        cv.line(image,(x1,y1),(x2,y2),(0,0,255),1)
    cv.imshow('lines_detected',image)


src = cv.imread('sudoku.png', 1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo', src)
line_detect_demo(src)
cv.waitKey(0)
cv.destroyWindow('demo')